package org.example.algorithm.dynamicProgramming;

/**
 * @Description: 最长上升子序列
 */

public class TestLengthOfLIS {
    public static void main(String[] args) {

        int[] nums1 = new int[]{10, 2, 2, 5, 1, 7, 101, 18};
        System.out.println(lengthOfLIS(nums1));
    }

    // 最长上升子序列
    static int lengthOfLIS(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n];
        int max = 1;
        dp[0] = 1;
        for (int i = 1; i < n; i++) {
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                    max = Math.max(dp[i], max);
                }
            }
        }
        return max;
    }
}
